package com.river.springbootdemo.algorithm;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class PracticeMap {
    @Data
    @EqualsAndHashCode
    @NoArgsConstructor
    @AllArgsConstructor
    static class Person{
       private String name;
       private Integer age;
    }
    public static void main(String[] args) {
        Person person = new Person("小明",12);
        Person person1 = new Person("小强",12);
        Person person2 = new Person("小陈",11);
        Person person3 = new Person("小李",123);
        Person person4 = new Person(null,123);
        List<Person> people =new ArrayList<>();
        people.add(person);
        people.add(person1);
        people.add(person2);
        people.add(person3);
        people.add(person4);
        Map<String, Integer> collect = people.stream().collect(Collectors.toMap(Person::getName,Person::getAge));
        HashMap<String, Person> map = new HashMap<>();
        map.put(null,person);

        System.out.println(collect);
        System.out.println(map);
    }
}
